<template>
    <div>
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-form">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="房型类型" prop="housingTypeId">
                        <el-select v-model="form.housingTypeId" placeholder="全部类型" disabled>
                            <el-option label="普通会员" :value="1"></el-option>
                            <el-option label="VIP会员" :value="2"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="产品名称" prop="productName">
                        <el-input v-model="form.productName"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="标准价" prop="normalPrice">
                        <el-input v-model="form.normalPrice"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="收款方式" prop="paymentTerm">
                        <el-radio-group v-model="form.paymentTerm">
                            <el-radio :label="1">预定付费</el-radio>
                            <el-radio :label="2">到店付费</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="住宿优惠">
                        <el-checkbox-group v-model="form.checkd">
                            <el-checkbox label="可使用优惠劵抵扣">可使用优惠劵抵扣</el-checkbox>
                            <el-checkbox label="可使用现金抵扣">可使用现金抵扣</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="会员差价" prop="memberPriceDifference">
                        <el-radio-group v-model="form.memberPriceDifference">
                            <el-radio :label="1">不设置</el-radio>
                            <el-radio :label="2">按折扣</el-radio>
                            <el-radio :label="3">按不同价格</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="早餐份数" prop="breakfastServings">
                        <el-input v-model="form.breakfastServings"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="房量数量" prop="roomQuantity">
                        <el-input v-model="form.roomQuantity"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script>
import { Update, Find } from '@/api/HousingPrice'
export default {
    data() {
        return {
            form: {
                id: 0,
                housingTypeId: "",
                productName: "",
                normalPrice: "",
                paymentTerm: "",
                accommodationDiscount: "",
                memberPriceDifference: "",
                breakfastServings: "",
                roomQuantity: "",
                checkd: []
            },
            rules: {
                housingTypeId: [
                    { required: true, message: '请输入房型类型', trigger: 'blur' }
                ],
                productName: [
                    { required: true, message: '请输入产品名称', trigger: 'blur' }
                ],
                normalPrice: [
                    { required: true, message: '请输入标准价', trigger: 'blur' }
                ],
                paymentTerm: [
                    { required: true, message: '请输入收款方式', trigger: 'blur' }
                ],
                memberPriceDifference: [
                    { required: true, message: '请输入会员差价', trigger: 'blur' }
                ],
                breakfastServings: [
                    { required: true, message: '请输入早餐份数', trigger: 'blur' }
                ],
                roomQuantity: [
                    { required: true, message: '请输入放量数量', trigger: 'blur' }
                ],
            },
        }
    },
    props: {
        Id: {
            type: Number,
        }
    },
    methods: {
        EditHousingPrice() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    let _this = this;
                    _this.form.accommodationDiscount = this.form.checkd.join(',');
                    console.log(_this.form);
                    Update(_this.form).then(res => {
                        if (res.messag == "产品名称已存在") {
                            this.$message.error("产品名称已存在");
                            return;
                        }
                        if (res) {
                            this.$message.success("修改成功");
                            location.reload();
                            return;
                        }
                        else {
                            this.$message.error("修改失败");
                            return;
                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        FindHousingPrice(Id) {
            Find(Id).then(res => {
                this.form = res.data;
                let checkdArr = [];
                checkdArr = res.data.accommodationDiscount.split(',');
                this.form.checkd = [];
                checkdArr.forEach((ele => {
                    if (ele) {
                        this.form.checkd.push(ele);
                    }
                }))
                console.log(this.form.checkd);
            })
        }
    },
    created() {
        this.form.id = this.Id;
        console.log(this.form.id)
        this.FindHousingPrice(this.form.id);
    }
}
</script>
<style></style>